library(dplyr)
#library(psych) #for pairs.panels, but could use other packages, e.g. GGalley
library(lavaan)
library(semPlot)
library(DiagrammeR)
library(tidyr)
library(ggplot2)

Import data

combined=read.csv("data/annual_averages/annual_data_compiled_regions.csv",stringsAsFactors = F)
cnames=read.csv("analysis/column_names_region.csv", stringsAsFactors = F)
dsub=filter(combined, Year>=1975) %>% arrange(Region,Year)
focaldata=dsub[,cnames$Datacolumn]
fvars=cnames$Shortname
colnames(focaldata)=fvars
regions=unique(focaldata$region)
regionorder=c("West","North","South")
years=1975:2021

focaldata = focaldata %>% 
  mutate(tzoop=hcope+clad+mysid+pcope,
         tzoop_c=hcope_c+clad_c+mysid_c+pcope_c,
         tzoop_e=hcope_e+clad_e+mysid_e+pcope_e,
         hzoop=hcope+clad,
         hzoop_c=hcope_c+clad_c,
         hzoop_e=hcope_e+clad_e,
         pzoop=mysid+pcope,
         pzoop_c=mysid_c+pcope_c,
         pzoop_e=mysid_e+pcope_e) 
fvars=c(fvars,"tzoop","tzoop_c","tzoop_e",
        "hzoop","hzoop_c","hzoop_e",
        "pzoop","pzoop_c","pzoop_e")
cnames=rbind(cnames,data.frame(Longname=NA,Shortname=c("tzoop","tzoop_c","tzoop_e",
                                                       "hzoop","hzoop_c","hzoop_e",
                                                       "pzoop","pzoop_c","pzoop_e"),
                               Diagramname=c("Total Zooplankton\nBiomass",
                                             "Total Zooplankton\nAbundance",
                                             "Total Zooplankton\nEnergy",
                                             "Herbivorous Zooplankton\nBiomass",
                                             "Herbivorous Zooplankton\nAbundance",
                                             "Herbivorous Zooplankton\nEnergy",
                                             "Predatory Zooplankton\nBiomass",
                                             "Predatory Zooplankton\nAbundance",
                                             "Predatory Zooplankton\nEnergy"),
                               Datacolumn=NA,Log="yes"))

#focal variables
varnames=c("temp","flow","nitrate","ammonia","dophos","chla","hcope","clad","amphi","pcope","mysid","potam","corbic","sside","estfish_bsot","estfish_bsmt","tzoop","tzoop_c","tzoop_e","hzoop","pzoop")

source("analysis/myLavaanPlot.r")

Data prep

Log transform, scale

#log transform
logvars=fvars[cnames$Log=="yes"]
logtrans=function(x) {
  x2=x[which(!is.na(x))]
  if(any(x2==0)) {log(x+min(x2[which(x2>0)],na.rm=T))}
  else {log(x)}
}
focaldatalog = focaldata %>% 
  mutate_at(logvars,logtrans)

#scale data
fdr0=focaldatalog
tvars=fvars[-(1:2)]

fdr=fdr0 %>% group_by(region) %>% 
  #lag
  mutate_at(tvars,list("1"=lag)) %>% 
  #scale
  mutate_at(-(1:2),scale) %>% 
  ungroup() %>% 
  as.data.frame() 

#detrended data
fdr_dtr=fdr0 %>% group_by(region) %>% 
  #detrend
  mutate_at(tvars,function(x) { 
    x<<-x
    if(!all(is.na(x))) {
      if((length(which(x==0))/length(x))<0.5) {
        x2<<-x
        x2[x2==0]=NA
        res<<-residuals(lm(x2~years))
        out=x
        out[which(!is.na(x2))]=res
        return(out)
      } else {return(x)}
    } else {return(x)}
  }) %>%
  #lag
  mutate_at(tvars,list("1"=lag)) %>% 
  #scale
  mutate_at(-(1:2),scale) %>% 
  ungroup() %>% 
  as.data.frame() 

Time series plots

Cross-correlation matrices

(only sig correlations shown… no correction for multiple comparisons)

Fish indices are not correlated in S and N!

Best predictor of fish

l_models = data.frame(l_model = c("tzoop","tzoop_c","tzoop_e",
                                  "hzoop","hzoop+pzoop","pzoop",
                                  "tzoop+amphi","tzoop_e+amphi",
                                  "hcope+clad+mysid",
                                  "hcope+clad+mysid+pcope",
                                  "hcope+clad+mysid+pcope+rotif_m",
                                  "hcope+mysid",
                                  "hcope+mysid+pcope",
                                  "hcope+mysid+amphi"))

#Midwater Trawl
westmods = purrr::map(l_models$l_model, ~lm(paste0("estfish_bsmt ~", .x), 
                                    data = filter(fdr_dtr,region=="West")))
names(westmods)=l_models$l_model
bbmle::AICctab(westmods,weights=T,delta=T)
##                                dAICc df weight
## tzoop_e                        0.0   3  0.1725
## tzoop_e+amphi                  0.1   4  0.1611
## tzoop                          0.2   3  0.1567
## tzoop+amphi                    0.2   4  0.1526
## hcope+clad+mysid               0.9   5  0.1085
## hzoop                          1.7   3  0.0730
## hzoop+pzoop                    2.8   4  0.0436
## pzoop                          3.3   3  0.0326
## hcope+clad+mysid+pcope         3.4   6  0.0316
## hcope+mysid                    3.7   4  0.0265
## hcope+mysid+amphi              3.9   5  0.0241
## hcope+clad+mysid+pcope+rotif_m 6.1   7  0.0081
## hcope+mysid+pcope              6.2   5  0.0076
## tzoop_c                        9.4   3  0.0015
northmods = purrr::map(l_models$l_model, ~lm(paste0("estfish_bsmt ~", .x), 
                                    data = filter(fdr_dtr,region=="North")))
names(northmods)=l_models$l_model
bbmle::AICctab(northmods,weights=T,delta=T)
##                                dAICc df weight
## tzoop+amphi                     0.0  4  0.2172
## tzoop_e+amphi                   0.4  4  0.1819
## tzoop                           0.5  3  0.1652
## tzoop_e                         1.1  3  0.1278
## pzoop                           1.5  3  0.1042
## hcope+clad+mysid+pcope+rotif_m  2.6  7  0.0587
## hcope+clad+mysid                3.0  5  0.0487
## hcope+clad+mysid+pcope          3.7  6  0.0341
## hzoop+pzoop                     3.9  4  0.0306
## hcope+mysid+amphi               5.7  5  0.0126
## hcope+mysid+pcope               6.3  5  0.0092
## hcope+mysid                     6.4  4  0.0090
## tzoop_c                        12.3  3  <0.001
## hzoop                          12.7  3  <0.001
southmods = purrr::map(l_models$l_model, ~lm(paste0("estfish_bsmt ~", .x), 
                                    data = filter(fdr_dtr,region=="South")))
names(southmods)=l_models$l_model
bbmle::AICctab(southmods,weights=T,delta=T)
##                                dAICc df weight
## hzoop                          0.0   3  0.1716
## tzoop                          0.3   3  0.1481
## tzoop_e                        0.3   3  0.1452
## tzoop_c                        0.5   3  0.1316
## pzoop                          0.9   3  0.1100
## hcope+clad+mysid               2.4   5  0.0521
## hzoop+pzoop                    2.4   4  0.0512
## hcope+mysid                    2.7   4  0.0451
## tzoop+amphi                    2.8   4  0.0433
## tzoop_e+amphi                  2.8   4  0.0424
## hcope+clad+mysid+pcope         4.0   6  0.0232
## hcope+mysid+pcope              4.8   5  0.0155
## hcope+mysid+amphi              5.3   5  0.0121
## hcope+clad+mysid+pcope+rotif_m 6.0   7  0.0087

tzoop and tzoop_e do pretty well in all regions. tzoop_c and hzoop+pzoop does poorly in all regions. amphi seem relevant in North (for midwater trawl), which is also where they are most abundant.

l_modelsw = data.frame(l_model = c("tzoop",
                                   "tzoop+marfish_bsmt"))
l_modelsns = data.frame(l_model = c("tzoop",
                                   "tzoop+amphi",
                                   "tzoop+amphi+sside",
                                   "tzoop+sside",
                                   "tzoop+corbic",
                                   "tzoop+corbic+sside"))

#Midwater Trawl
westmods = purrr::map(l_modelsw$l_model, ~lm(paste0("estfish_bsmt ~", .x), 
                                    data = filter(fdr_dtr,region=="West")))
names(westmods)=l_modelsw$l_model
bbmle::AICctab(westmods,weights=T,delta=T)
##                    dAICc df weight
## tzoop              0.0   3  0.74  
## tzoop+marfish_bsmt 2.1   4  0.26
northmods = purrr::map(l_modelsns$l_model, ~lm(paste0("estfish_bsmt ~", .x), 
                                    data = filter(fdr_dtr,region=="North")))
names(northmods)=l_modelsns$l_model
bbmle::AICctab(northmods,weights=T,delta=T)
##                    dAICc df weight
## tzoop+amphi+sside  0.0   5  0.323 
## tzoop+sside        0.3   4  0.279 
## tzoop+corbic+sside 1.5   5  0.154 
## tzoop+amphi        2.1   4  0.114 
## tzoop              2.6   3  0.087 
## tzoop+corbic       4.1   4  0.043
southmods = purrr::map(l_modelsns$l_model, ~lm(paste0("estfish_bsmt ~", .x), 
                                    data = filter(fdr_dtr,region=="South")))
names(southmods)=l_modelsns$l_model
bbmle::AICctab(southmods,weights=T,delta=T)
##                    dAICc df weight
## tzoop+corbic       0.0   4  0.454 
## tzoop+corbic+sside 1.9   5  0.173 
## tzoop              2.1   3  0.162 
## tzoop+sside        2.5   4  0.128 
## tzoop+amphi        4.5   4  0.047 
## tzoop+amphi+sside  5.1   5  0.035

SEM model

With and without detrending.

#west has no ssides, corbic
 
#1
# modwest='zoop=~hcope+mysid
#         fish=~estfish_bsmt+estfish_bsot
#         zoop~chla+potam+flow
#         chla~potam+flow
#         fish~zoop+flow
# '

#2
# modwest='chla~potam+flow
#         tzoop~chla+potam+flow
#         estfish_bsmt~tzoop+flow
#         estfish_bsot~tzoop+flow
# '

#3
# modwest='chla~potam+flow+temp+secchi
#         tzoop~chla+potam+flow+temp+secchi
#         amphi~chla+potam+flow+temp+secchi
#         estfish_bsmt~tzoop+amphi+flow
#         #estfish_bsot~tzoop+amphi+flow+temp+secchi
#         amphi~~tzoop
# '
#4
modwest='chla~potam+flow+temp+secchi
        hzoop~chla+potam+flow+temp+secchi
        pzoop~chla+potam+flow+temp+secchi+hzoop
        amphi~chla+potam+flow+temp+secchi
        estfish_bsmt~hzoop+pzoop+amphi+flow+temp+secchi #+marfish_bsmt
        amphi~~hzoop+pzoop
'

modfitwest=sem(modwest, data=filter(fdr,region=="West"))
modfitwest_dtr=sem(modwest, data=filter(fdr_dtr,region=="West"))
summary(modfitwest, standardized=T, rsq=T)
## lavaan 0.6-4 ended normally after 39 iterations
## 
##   Optimization method                           NLMINB
##   Number of free parameters                         33
## 
##                                                   Used       Total
##   Number of observations                            40          47
## 
##   Estimator                                         ML
##   Model Fit Test Statistic                       3.390
##   Degrees of freedom                                 2
##   P-value (Chi-square)                           0.184
## 
## Parameter Estimates:
## 
##   Information                                 Expected
##   Information saturated (h1) model          Structured
##   Standard Errors                             Standard
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   chla ~                                                                
##     potam            -0.361    0.148   -2.438    0.015   -0.361   -0.422
##     flow              0.148    0.153    0.964    0.335    0.148    0.179
##     temp              0.010    0.131    0.074    0.941    0.010    0.011
##     secchi            0.126    0.196    0.640    0.522    0.126    0.124
##   hzoop ~                                                               
##     chla              0.650    0.098    6.649    0.000    0.650    0.659
##     potam            -0.161    0.098   -1.642    0.101   -0.161   -0.191
##     flow              0.189    0.096    1.964    0.049    0.189    0.231
##     temp              0.160    0.081    1.966    0.049    0.160    0.188
##     secchi            0.113    0.122    0.923    0.356    0.113    0.113
##   pzoop ~                                                               
##     chla              0.541    0.127    4.270    0.000    0.541    0.529
##     potam            -0.060    0.090   -0.664    0.507   -0.060   -0.069
##     flow             -0.152    0.090   -1.695    0.090   -0.152   -0.180
##     temp              0.116    0.076    1.535    0.125    0.116    0.133
##     secchi            0.016    0.110    0.145    0.884    0.016    0.016
##     hzoop             0.404    0.141    2.867    0.004    0.404    0.391
##   amphi ~                                                               
##     chla              0.050    0.143    0.352    0.725    0.050    0.047
##     potam             0.298    0.143    2.080    0.038    0.298    0.324
##     flow              0.377    0.140    2.682    0.007    0.377    0.423
##     temp             -0.376    0.119   -3.165    0.002   -0.376   -0.406
##     secchi            0.458    0.178    2.568    0.010    0.458    0.422
##   estfish_bsmt ~                                                        
##     hzoop             0.044    0.218    0.203    0.839    0.044    0.038
##     pzoop             0.600    0.198    3.033    0.002    0.600    0.529
##     amphi             0.027    0.148    0.180    0.857    0.027    0.025
##     flow              0.372    0.151    2.452    0.014    0.372    0.388
##     temp              0.057    0.122    0.469    0.639    0.057    0.058
##     secchi           -0.155    0.173   -0.892    0.372   -0.155   -0.133
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .hzoop ~~                                                              
##    .amphi            -0.135    0.055   -2.433    0.015   -0.135   -0.417
##  .pzoop ~~                                                              
##    .amphi            -0.111    0.045   -2.461    0.014   -0.111   -0.384
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .chla              0.578    0.129    4.472    0.000    0.578    0.793
##    .hzoop             0.221    0.049    4.472    0.000    0.221    0.311
##    .pzoop             0.176    0.039    4.472    0.000    0.176    0.232
##    .amphi             0.472    0.106    4.472    0.000    0.472    0.560
##    .estfish_bsmt      0.397    0.089    4.472    0.000    0.397    0.407
## 
## R-Square:
##                    Estimate
##     chla              0.207
##     hzoop             0.689
##     pzoop             0.768
##     amphi             0.440
##     estfish_bsmt      0.593
summary(modfitwest_dtr, standardized=T, rsq=T)
## lavaan 0.6-4 ended normally after 32 iterations
## 
##   Optimization method                           NLMINB
##   Number of free parameters                         33
## 
##                                                   Used       Total
##   Number of observations                            40          47
## 
##   Estimator                                         ML
##   Model Fit Test Statistic                       2.897
##   Degrees of freedom                                 2
##   P-value (Chi-square)                           0.235
## 
## Parameter Estimates:
## 
##   Information                                 Expected
##   Information saturated (h1) model          Structured
##   Standard Errors                             Standard
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   chla ~                                                                
##     potam             0.037    0.157    0.236    0.814    0.037    0.039
##     flow              0.321    0.178    1.799    0.072    0.321    0.342
##     temp             -0.287    0.166   -1.736    0.083   -0.287   -0.298
##     secchi            0.466    0.234    1.994    0.046    0.466    0.388
##   hzoop ~                                                               
##     chla              0.654    0.112    5.817    0.000    0.654    0.654
##     potam            -0.107    0.112   -0.959    0.338   -0.107   -0.113
##     flow              0.283    0.132    2.144    0.032    0.283    0.302
##     temp              0.133    0.122    1.091    0.275    0.133    0.138
##     secchi            0.240    0.174    1.374    0.169    0.240    0.199
##   pzoop ~                                                               
##     chla              0.445    0.127    3.517    0.000    0.445    0.509
##     potam             0.037    0.094    0.397    0.691    0.037    0.045
##     flow             -0.089    0.115   -0.771    0.441   -0.089   -0.109
##     temp              0.067    0.103    0.649    0.516    0.067    0.079
##     secchi            0.107    0.148    0.722    0.471    0.107    0.101
##     hzoop             0.297    0.131    2.267    0.023    0.297    0.339
##   amphi ~                                                               
##     chla              0.228    0.143    1.595    0.111    0.228    0.237
##     potam             0.058    0.142    0.407    0.684    0.058    0.063
##     flow              0.336    0.168    2.004    0.045    0.336    0.372
##     temp             -0.196    0.155   -1.265    0.206   -0.196   -0.211
##     secchi            0.233    0.222    1.053    0.292    0.233    0.201
##   estfish_bsmt ~                                                        
##     hzoop             0.063    0.179    0.351    0.726    0.063    0.061
##     pzoop             0.481    0.194    2.482    0.013    0.481    0.410
##     amphi             0.064    0.142    0.453    0.650    0.064    0.060
##     flow              0.426    0.174    2.445    0.014    0.426    0.442
##     temp              0.008    0.141    0.057    0.955    0.008    0.008
##     secchi           -0.055    0.217   -0.252    0.801   -0.055   -0.044
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .hzoop ~~                                                              
##    .amphi            -0.199    0.085   -2.349    0.019   -0.199   -0.400
##  .pzoop ~~                                                              
##    .amphi            -0.122    0.063   -1.944    0.052   -0.122   -0.296
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .chla              0.775    0.173    4.472    0.000    0.775    0.840
##    .hzoop             0.392    0.088    4.472    0.000    0.392    0.425
##    .pzoop             0.269    0.060    4.472    0.000    0.269    0.381
##    .amphi             0.633    0.141    4.472    0.000    0.633    0.739
##    .estfish_bsmt      0.537    0.120    4.472    0.000    0.537    0.551
## 
## R-Square:
##                    Estimate
##     chla              0.160
##     hzoop             0.575
##     pzoop             0.619
##     amphi             0.261
##     estfish_bsmt      0.449
# par(mfrow=c(1,2))
# semPaths(modfitwest, "std", edge.label.cex = 1, residuals = F)
# semPaths(modfitwest, "par", edge.label.cex = 1, residuals = F)

labelswest <- createLabels(modfitwest, cnames)

# residuals(modfitwest)
# modificationindices(modfitwest)
#no potam

#1
# modnorth='zoop=~hcope+mysid
#         #fish=~estfish_bsmt+estfish_bsot
#         zoop~chla+potam+flow
#         chla~potam+flow
#         estfish_bsmt~zoop+flow
#         estfish_bsot~zoop+flow
# '
# modnorth='zoop=~clad
#         zoop~chla+corbic+potam+flow
#         chla~corbic+potam+flow
#         estfish_bsmt~zoop+flow+sside+chla
#         estfish_bsot~zoop+flow+sside+chla
# '

#2
# modnorth='chla~corbic+potam+flow
#         tzoop~chla+corbic+potam+flow
#         estfish_bsmt~tzoop+flow+chla
#         estfish_bsot~tzoop+flow
# '

#3
# modnorth='chla~corbic+potam+flow+temp+secchi
#         tzoop~chla+corbic+potam+flow+temp+secchi
#         amphi~chla+corbic+potam+flow+temp+secchi
#         estfish_bsmt~tzoop+amphi+flow+temp+secchi+chla+sside
#         #estfish_bsot~tzoop+amphi+flow+temp+secchi+sside
#         amphi~~tzoop
# '
#4
modnorth='chla~corbic+flow+temp+secchi
        hzoop~chla+corbic+flow+temp+secchi
        pzoop~chla+corbic+flow+temp+secchi+hzoop
        amphi~chla+corbic+flow+temp+secchi
        estfish_bsmt~hzoop+pzoop+amphi+flow+temp+secchi+chla+sside
        amphi~~hzoop+pzoop
'

modfitnorth=sem(modnorth, data=filter(fdr,region=="North"))
modfitnorth_dtr=sem(modnorth, data=filter(fdr_dtr,region=="North"))
summary(modfitnorth, standardized=T, rsq=T)
## lavaan 0.6-4 ended normally after 40 iterations
## 
##   Optimization method                           NLMINB
##   Number of free parameters                         35
## 
##                                                   Used       Total
##   Number of observations                            40          47
## 
##   Estimator                                         ML
##   Model Fit Test Statistic                       6.981
##   Degrees of freedom                                 5
##   P-value (Chi-square)                           0.222
## 
## Parameter Estimates:
## 
##   Information                                 Expected
##   Information saturated (h1) model          Structured
##   Standard Errors                             Standard
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   chla ~                                                                
##     corbic            0.345    0.127    2.713    0.007    0.345    0.407
##     flow              0.106    0.146    0.723    0.469    0.106    0.124
##     temp              0.134    0.138    0.972    0.331    0.134    0.153
##     secchi           -0.168    0.140   -1.202    0.229   -0.168   -0.170
##   hzoop ~                                                               
##     chla              0.062    0.112    0.552    0.581    0.062    0.062
##     corbic            0.262    0.098    2.669    0.008    0.262    0.307
##     flow             -0.226    0.105   -2.162    0.031   -0.226   -0.263
##     temp              0.321    0.099    3.238    0.001    0.321    0.363
##     secchi           -0.489    0.101   -4.848    0.000   -0.489   -0.493
##   pzoop ~                                                               
##     chla              0.642    0.093    6.880    0.000    0.642    0.574
##     corbic            0.345    0.088    3.908    0.000    0.345    0.363
##     flow             -0.338    0.092   -3.686    0.000   -0.338   -0.353
##     temp              0.184    0.092    1.997    0.046    0.184    0.187
##     secchi           -0.105    0.105   -0.994    0.320   -0.105   -0.095
##     hzoop             0.047    0.131    0.362    0.717    0.047    0.043
##   amphi ~                                                               
##     chla              0.340    0.137    2.471    0.013    0.340    0.313
##     corbic            0.388    0.120    3.224    0.001    0.388    0.420
##     flow             -0.041    0.128   -0.323    0.747   -0.041   -0.045
##     temp             -0.505    0.122   -4.153    0.000   -0.505   -0.528
##     secchi            0.160    0.124    1.295    0.195    0.160    0.149
##   estfish_bsmt ~                                                        
##     hzoop            -0.202    0.194   -1.040    0.298   -0.202   -0.181
##     pzoop            -0.186    0.225   -0.827    0.408   -0.186   -0.185
##     amphi             0.313    0.159    1.968    0.049    0.313    0.302
##     flow              0.110    0.142    0.776    0.438    0.110    0.114
##     temp              0.518    0.176    2.944    0.003    0.518    0.523
##     secchi            0.121    0.160    0.759    0.448    0.121    0.109
##     chla              0.644    0.209    3.083    0.002    0.644    0.572
##     sside            -0.167    0.159   -1.048    0.295   -0.167   -0.134
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .hzoop ~~                                                              
##    .amphi            -0.070    0.053   -1.335    0.182   -0.070   -0.216
##  .pzoop ~~                                                              
##    .amphi             0.044    0.042    1.047    0.295    0.044    0.164
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .chla              0.528    0.118    4.472    0.000    0.528    0.692
##    .hzoop             0.266    0.059    4.472    0.000    0.266    0.344
##    .pzoop             0.183    0.041    4.472    0.000    0.183    0.191
##    .amphi             0.399    0.089    4.472    0.000    0.399    0.443
##    .estfish_bsmt      0.433    0.097    4.472    0.000    0.433    0.448
## 
## R-Square:
##                    Estimate
##     chla              0.308
##     hzoop             0.656
##     pzoop             0.809
##     amphi             0.557
##     estfish_bsmt      0.552
summary(modfitnorth_dtr, standardized=T, rsq=T)
## lavaan 0.6-4 ended normally after 32 iterations
## 
##   Optimization method                           NLMINB
##   Number of free parameters                         35
## 
##                                                   Used       Total
##   Number of observations                            40          47
## 
##   Estimator                                         ML
##   Model Fit Test Statistic                       7.226
##   Degrees of freedom                                 5
##   P-value (Chi-square)                           0.204
## 
## Parameter Estimates:
## 
##   Information                                 Expected
##   Information saturated (h1) model          Structured
##   Standard Errors                             Standard
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   chla ~                                                                
##     corbic            0.426    0.170    2.509    0.012    0.426    0.421
##     flow              0.079    0.177    0.449    0.653    0.079    0.082
##     temp              0.177    0.164    1.077    0.281    0.177    0.178
##     secchi           -0.272    0.158   -1.715    0.086   -0.272   -0.270
##   hzoop ~                                                               
##     chla              0.102    0.123    0.828    0.408    0.102    0.116
##     corbic            0.212    0.142    1.499    0.134    0.212    0.240
##     flow             -0.299    0.138   -2.174    0.030   -0.299   -0.354
##     temp              0.316    0.129    2.449    0.014    0.316    0.365
##     secchi           -0.300    0.127   -2.358    0.018   -0.300   -0.342
##   pzoop ~                                                               
##     chla              0.663    0.095    6.967    0.000    0.663    0.635
##     corbic            0.378    0.112    3.377    0.001    0.378    0.358
##     flow             -0.406    0.112   -3.623    0.000   -0.406   -0.401
##     temp              0.193    0.106    1.813    0.070    0.193    0.186
##     secchi           -0.035    0.105   -0.336    0.737   -0.035   -0.033
##     hzoop             0.019    0.122    0.157    0.875    0.019    0.016
##   amphi ~                                                               
##     chla              0.295    0.111    2.666    0.008    0.295    0.307
##     corbic            0.458    0.128    3.582    0.000    0.458    0.471
##     flow             -0.062    0.124   -0.502    0.616   -0.062   -0.067
##     temp             -0.394    0.116   -3.381    0.001   -0.394   -0.413
##     secchi           -0.031    0.115   -0.268    0.789   -0.031   -0.032
##   estfish_bsmt ~                                                        
##     hzoop            -0.041    0.141   -0.290    0.772   -0.041   -0.037
##     pzoop             0.068    0.178    0.380    0.704    0.068    0.072
##     amphi             0.261    0.150    1.743    0.081    0.261    0.256
##     flow              0.272    0.133    2.042    0.041    0.272    0.286
##     temp              0.494    0.148    3.349    0.001    0.494    0.508
##     secchi           -0.031    0.111   -0.277    0.782   -0.031   -0.031
##     chla              0.354    0.166    2.132    0.033    0.354    0.361
##     sside            -0.175    0.112   -1.560    0.119   -0.175   -0.164
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .hzoop ~~                                                              
##    .amphi            -0.069    0.068   -1.014    0.310   -0.069   -0.162
##  .pzoop ~~                                                              
##    .amphi             0.057    0.051    1.110    0.267    0.057    0.176
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .chla              0.776    0.173    4.472    0.000    0.776    0.799
##    .hzoop             0.468    0.105    4.472    0.000    0.468    0.631
##    .pzoop             0.276    0.062    4.472    0.000    0.276    0.261
##    .amphi             0.380    0.085    4.472    0.000    0.380    0.424
##    .estfish_bsmt      0.386    0.086    4.472    0.000    0.386    0.413
## 
## R-Square:
##                    Estimate
##     chla              0.201
##     hzoop             0.369
##     pzoop             0.739
##     amphi             0.576
##     estfish_bsmt      0.587
# par(mfrow=c(1,2))
# semPaths(modfitnorth, "std", edge.label.cex = 1, residuals = F)
# semPaths(modfitnorth, "par", edge.label.cex = 1, residuals = F)

labelsnorth <- createLabels(modfitnorth, cnames)

# residuals(modfitnorth)
# modificationindices(modfitnorth)
#no potam

#1
# modsouth='zoop=~hcope+mysid
#         #fish=~estfish_bsmt+estfish_bsot
#         zoop~chla+corbic+flow
#         chla~corbic+flow
#         estfish_bsmt~zoop+flow
#         estfish_bsot~zoop+flow
# '

#2
# modsouth='chla~corbic+flow
#         tzoop~chla+corbic+flow
#         estfish_bsmt~tzoop+flow+corbic+sside
#         estfish_bsot~tzoop+flow+corbic+sside
# '

#3
# modsouth='chla~corbic+flow+temp+secchi
#         tzoop~chla+corbic+flow+temp+secchi
#         amphi~chla+corbic+flow+temp+secchi
#         estfish_bsmt~tzoop+amphi+flow+temp+secchi+corbic+sside
#         #estfish_bsot~tzoop+amphi+flow+temp+secchi+corbic+sside
#         amphi~~tzoop
# '
#4
modsouth='chla~corbic+flow+temp+secchi
        hzoop~chla+corbic+flow+temp+secchi
        pzoop~chla+corbic+flow+temp+secchi+hzoop
        amphi~chla+corbic+flow+temp+secchi
        estfish_bsmt~hzoop+pzoop+amphi+flow+temp+secchi+corbic+sside
        amphi~~hzoop+pzoop
'

modfitsouth=sem(modsouth, data=filter(fdr,region=="South"))
modfitsouth_dtr=sem(modsouth, data=filter(fdr_dtr,region=="South"))
summary(modfitsouth, standardized=T, rsq=T)
## lavaan 0.6-4 ended normally after 32 iterations
## 
##   Optimization method                           NLMINB
##   Number of free parameters                         35
## 
##                                                   Used       Total
##   Number of observations                            40          47
## 
##   Estimator                                         ML
##   Model Fit Test Statistic                       8.954
##   Degrees of freedom                                 5
##   P-value (Chi-square)                           0.111
## 
## Parameter Estimates:
## 
##   Information                                 Expected
##   Information saturated (h1) model          Structured
##   Standard Errors                             Standard
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   chla ~                                                                
##     corbic            0.158    0.147    1.076    0.282    0.158    0.155
##     flow              0.159    0.149    1.067    0.286    0.159    0.163
##     temp              0.440    0.148    2.979    0.003    0.440    0.438
##     secchi           -0.318    0.152   -2.092    0.036   -0.318   -0.286
##   hzoop ~                                                               
##     chla              0.473    0.139    3.403    0.001    0.473    0.481
##     corbic            0.301    0.131    2.295    0.022    0.301    0.299
##     flow             -0.097    0.133   -0.735    0.462   -0.097   -0.101
##     temp              0.194    0.144    1.352    0.176    0.194    0.197
##     secchi            0.091    0.141    0.644    0.519    0.091    0.083
##   pzoop ~                                                               
##     chla              0.513    0.123    4.153    0.000    0.513    0.547
##     corbic           -0.051    0.109   -0.468    0.640   -0.051   -0.053
##     flow              0.045    0.104    0.433    0.665    0.045    0.049
##     temp              0.246    0.115    2.141    0.032    0.246    0.261
##     secchi           -0.135    0.111   -1.216    0.224   -0.135   -0.129
##     hzoop             0.111    0.124    0.894    0.372    0.111    0.116
##   amphi ~                                                               
##     chla              0.062    0.146    0.425    0.671    0.062    0.084
##     corbic           -0.053    0.138   -0.387    0.699   -0.053   -0.070
##     flow             -0.115    0.139   -0.827    0.408   -0.115   -0.159
##     temp              0.136    0.151    0.904    0.366    0.136    0.183
##     secchi            0.078    0.148    0.526    0.599    0.078    0.095
##   estfish_bsmt ~                                                        
##     hzoop            -0.325    0.168   -1.938    0.053   -0.325   -0.329
##     pzoop             0.164    0.186    0.883    0.377    0.164    0.158
##     amphi             0.007    0.167    0.045    0.964    0.007    0.006
##     flow             -0.147    0.148   -0.998    0.319   -0.147   -0.155
##     temp              0.002    0.171    0.014    0.989    0.002    0.002
##     secchi           -0.488    0.229   -2.130    0.033   -0.488   -0.453
##     corbic            0.506    0.174    2.917    0.004    0.506    0.509
##     sside             0.114    0.292    0.390    0.697    0.114    0.090
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .hzoop ~~                                                              
##    .amphi             0.054    0.077    0.697    0.486    0.054    0.111
##  .pzoop ~~                                                              
##    .amphi            -0.008    0.059   -0.142    0.887   -0.008   -0.022
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .chla              0.596    0.133    4.472    0.000    0.596    0.573
##    .hzoop             0.460    0.103    4.472    0.000    0.460    0.458
##    .pzoop             0.282    0.063    4.472    0.000    0.282    0.308
##    .amphi             0.507    0.113    4.472    0.000    0.507    0.890
##    .estfish_bsmt      0.556    0.124    4.472    0.000    0.556    0.567
## 
## R-Square:
##                    Estimate
##     chla              0.427
##     hzoop             0.542
##     pzoop             0.692
##     amphi             0.110
##     estfish_bsmt      0.433
summary(modfitsouth_dtr, standardized=T, rsq=T)
## lavaan 0.6-4 ended normally after 25 iterations
## 
##   Optimization method                           NLMINB
##   Number of free parameters                         35
## 
##                                                   Used       Total
##   Number of observations                            40          47
## 
##   Estimator                                         ML
##   Model Fit Test Statistic                       7.040
##   Degrees of freedom                                 5
##   P-value (Chi-square)                           0.218
## 
## Parameter Estimates:
## 
##   Information                                 Expected
##   Information saturated (h1) model          Structured
##   Standard Errors                             Standard
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   chla ~                                                                
##     corbic            0.064    0.158    0.408    0.683    0.064    0.063
##     flow              0.208    0.175    1.189    0.234    0.208    0.213
##     temp              0.450    0.173    2.599    0.009    0.450    0.447
##     secchi            0.004    0.151    0.025    0.980    0.004    0.004
##   hzoop ~                                                               
##     chla              0.417    0.132    3.162    0.002    0.417    0.415
##     corbic            0.262    0.132    1.988    0.047    0.262    0.257
##     flow             -0.108    0.149   -0.727    0.467   -0.108   -0.110
##     temp              0.196    0.156    1.257    0.209    0.196    0.194
##     secchi            0.102    0.126    0.810    0.418    0.102    0.102
##   pzoop ~                                                               
##     chla              0.519    0.136    3.807    0.000    0.519    0.511
##     corbic           -0.130    0.128   -1.020    0.308   -0.130   -0.126
##     flow              0.065    0.138    0.471    0.638    0.065    0.066
##     temp              0.281    0.147    1.908    0.056    0.281    0.275
##     secchi            0.076    0.118    0.644    0.520    0.076    0.075
##     hzoop             0.117    0.146    0.798    0.425    0.117    0.115
##   amphi ~                                                               
##     chla              0.085    0.122    0.695    0.487    0.085    0.113
##     corbic           -0.007    0.122   -0.060    0.952   -0.007   -0.010
##     flow             -0.114    0.138   -0.829    0.407   -0.114   -0.155
##     temp              0.156    0.145    1.082    0.279    0.156    0.206
##     secchi           -0.044    0.117   -0.373    0.709   -0.044   -0.058
##   estfish_bsmt ~                                                        
##     hzoop            -0.335    0.172   -1.943    0.052   -0.335   -0.344
##     pzoop             0.126    0.165    0.760    0.447    0.126    0.131
##     amphi             0.012    0.193    0.062    0.950    0.012    0.009
##     flow             -0.169    0.170   -0.992    0.321   -0.169   -0.177
##     temp             -0.002    0.189   -0.009    0.993   -0.002   -0.002
##     secchi           -0.258    0.164   -1.576    0.115   -0.258   -0.264
##     corbic            0.478    0.172    2.786    0.005    0.478    0.482
##     sside             0.074    0.197    0.375    0.708    0.074    0.063
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .hzoop ~~                                                              
##    .amphi             0.067    0.089    0.755    0.450    0.067    0.120
##  .pzoop ~~                                                              
##    .amphi             0.004    0.081    0.053    0.958    0.004    0.008
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .chla              0.863    0.193    4.472    0.000    0.863    0.835
##    .hzoop             0.599    0.134    4.472    0.000    0.599    0.576
##    .pzoop             0.513    0.115    4.472    0.000    0.513    0.482
##    .amphi             0.516    0.115    4.472    0.000    0.516    0.879
##    .estfish_bsmt      0.762    0.170    4.472    0.000    0.762    0.776
## 
## R-Square:
##                    Estimate
##     chla              0.165
##     hzoop             0.424
##     pzoop             0.518
##     amphi             0.121
##     estfish_bsmt      0.224
# par(mfrow=c(1,2))
# semPaths(modfitsouth, "std", edge.label.cex = 1, residuals = F)
# semPaths(modfitsouth, "par", edge.label.cex = 1, residuals = F)

labelssouth <- createLabels(modfitsouth, cnames)

# residuals(modfitsouth)
# modificationindices(modfitsouth)

Nice plots

Original units

West

North

South

Detrended

West

North

South

Older SEM model (h and p zoop split)

With and without detrending.

#west has no ssides, corbic

modwest='chla~potam
        potam~flow
        hzoop~chla+potam+flow
        pzoop~chla+potam+flow+hzoop
        estfish_bsmt~hzoop+pzoop+flow
        estfish_bsot~hzoop+pzoop+flow
'

modfitwest=sem(modwest, data=filter(fdr,region=="West"))
modfitwest_dtr=sem(modwest, data=filter(fdr_dtr,region=="West"))
summary(modfitwest, standardized=T, rsq=T)
## lavaan 0.6-4 ended normally after 33 iterations
## 
##   Optimization method                           NLMINB
##   Number of free parameters                         22
## 
##                                                   Used       Total
##   Number of observations                            40          47
## 
##   Estimator                                         ML
##   Model Fit Test Statistic                       5.981
##   Degrees of freedom                                 5
##   P-value (Chi-square)                           0.308
## 
## Parameter Estimates:
## 
##   Information                                 Expected
##   Information saturated (h1) model          Structured
##   Standard Errors                             Standard
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   chla ~                                                                
##     potam            -0.370    0.122   -3.036    0.002   -0.370   -0.433
##   potam ~                                                               
##     flow             -0.430    0.137   -3.133    0.002   -0.430   -0.444
##   hzoop ~                                                               
##     chla              0.665    0.103    6.463    0.000    0.665    0.678
##     potam            -0.142    0.096   -1.478    0.139   -0.142   -0.170
##     flow              0.085    0.086    0.987    0.323    0.085    0.104
##   pzoop ~                                                               
##     chla              0.498    0.127    3.924    0.000    0.498    0.481
##     potam            -0.057    0.085   -0.673    0.501   -0.057   -0.065
##     flow             -0.209    0.075   -2.793    0.005   -0.209   -0.244
##     hzoop             0.476    0.136    3.491    0.000    0.476    0.451
##   estfish_bsmt ~                                                        
##     hzoop             0.040    0.218    0.182    0.856    0.040    0.034
##     pzoop             0.611    0.196    3.112    0.002    0.611    0.556
##     flow              0.434    0.111    3.911    0.000    0.434    0.460
##   estfish_bsot ~                                                        
##     hzoop             0.144    0.220    0.655    0.512    0.144    0.124
##     pzoop             0.517    0.198    2.609    0.009    0.517    0.471
##     flow              0.410    0.112    3.662    0.000    0.410    0.436
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .estfish_bsmt ~~                                                       
##    .estfish_bsot      0.062    0.066    0.946    0.344    0.062    0.151
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .chla              0.592    0.132    4.472    0.000    0.592    0.813
##    .potam             0.801    0.179    4.472    0.000    0.801    0.803
##    .hzoop             0.251    0.056    4.472    0.000    0.251    0.358
##    .pzoop             0.187    0.042    4.472    0.000    0.187    0.239
##    .estfish_bsmt      0.407    0.091    4.472    0.000    0.407    0.430
##    .estfish_bsot      0.414    0.093    4.472    0.000    0.414    0.440
## 
## R-Square:
##                    Estimate
##     chla              0.187
##     potam             0.197
##     hzoop             0.642
##     pzoop             0.761
##     estfish_bsmt      0.570
##     estfish_bsot      0.560
summary(modfitwest_dtr, standardized=T, rsq=T)
## lavaan 0.6-4 ended normally after 26 iterations
## 
##   Optimization method                           NLMINB
##   Number of free parameters                         22
## 
##                                                   Used       Total
##   Number of observations                            40          47
## 
##   Estimator                                         ML
##   Model Fit Test Statistic                       8.863
##   Degrees of freedom                                 5
##   P-value (Chi-square)                           0.115
## 
## Parameter Estimates:
## 
##   Information                                 Expected
##   Information saturated (h1) model          Structured
##   Standard Errors                             Standard
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   chla ~                                                                
##     potam            -0.061    0.150   -0.409    0.682   -0.061   -0.065
##   potam ~                                                               
##     flow             -0.423    0.141   -2.996    0.003   -0.423   -0.428
##   hzoop ~                                                               
##     chla              0.669    0.109    6.121    0.000    0.669    0.681
##     potam            -0.048    0.115   -0.420    0.675   -0.048   -0.052
##     flow              0.138    0.113    1.217    0.223    0.138    0.150
##   pzoop ~                                                               
##     chla              0.417    0.121    3.446    0.001    0.417    0.468
##     potam             0.068    0.092    0.739    0.460    0.068    0.080
##     flow             -0.163    0.092   -1.772    0.076   -0.163   -0.195
##     hzoop             0.347    0.126    2.752    0.006    0.347    0.382
##   estfish_bsmt ~                                                        
##     hzoop             0.052    0.176    0.296    0.767    0.052    0.051
##     pzoop             0.475    0.192    2.468    0.014    0.475    0.424
##     flow              0.473    0.124    3.816    0.000    0.473    0.505
##   estfish_bsot ~                                                        
##     hzoop             0.152    0.175    0.871    0.384    0.152    0.148
##     pzoop             0.429    0.191    2.244    0.025    0.429    0.379
##     flow              0.440    0.123    3.578    0.000    0.440    0.466
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .estfish_bsmt ~~                                                       
##    .estfish_bsot      0.080    0.086    0.938    0.348    0.080    0.150
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .chla              0.919    0.205    4.472    0.000    0.919    0.996
##    .potam             0.836    0.187    4.472    0.000    0.836    0.817
##    .hzoop             0.439    0.098    4.472    0.000    0.439    0.494
##    .pzoop             0.278    0.062    4.472    0.000    0.278    0.380
##    .estfish_bsmt      0.540    0.121    4.472    0.000    0.540    0.586
##    .estfish_bsot      0.533    0.119    4.472    0.000    0.533    0.568
## 
## R-Square:
##                    Estimate
##     chla              0.004
##     potam             0.183
##     hzoop             0.506
##     pzoop             0.620
##     estfish_bsmt      0.414
##     estfish_bsot      0.432
labelswest <- createLabels(modfitwest, cnames)

# residuals(modfitwest)
# modificationindices(modfitwest)
modnorth='chla~corbic+potam
        potam~flow
        corbic~flow
        hzoop~chla+corbic+potam+flow
        pzoop~chla+corbic+potam+flow+hzoop
        estfish_bsmt~hzoop+pzoop+flow
        estfish_bsot~hzoop+pzoop+flow
'

modfitnorth=sem(modnorth, data=filter(fdr,region=="North"))
modfitnorth_dtr=sem(modnorth, data=filter(fdr_dtr,region=="North"))
summary(modfitnorth, standardized=T, rsq=T)
## lavaan 0.6-4 ended normally after 24 iterations
## 
##   Optimization method                           NLMINB
##   Number of free parameters                         27
## 
##                                                   Used       Total
##   Number of observations                            40          47
## 
##   Estimator                                         ML
##   Model Fit Test Statistic                      13.130
##   Degrees of freedom                                 8
##   P-value (Chi-square)                           0.107
## 
## Parameter Estimates:
## 
##   Information                                 Expected
##   Information saturated (h1) model          Structured
##   Standard Errors                             Standard
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   chla ~                                                                
##     corbic            0.363    0.118    3.086    0.002    0.363    0.435
##     potam            -0.130    0.120   -1.083    0.279   -0.130   -0.153
##   potam ~                                                               
##     flow             -0.498    0.134   -3.708    0.000   -0.498   -0.506
##   corbic ~                                                              
##     flow              0.398    0.146    2.721    0.007    0.398    0.395
##   hzoop ~                                                               
##     chla              0.283    0.158    1.796    0.072    0.283    0.275
##     corbic            0.319    0.138    2.316    0.021    0.319    0.370
##     potam             0.086    0.138    0.626    0.531    0.086    0.098
##     flow             -0.282    0.143   -1.971    0.049   -0.282   -0.325
##   pzoop ~                                                               
##     chla              0.673    0.099    6.826    0.000    0.673    0.593
##     corbic            0.332    0.088    3.762    0.000    0.332    0.350
##     potam             0.041    0.083    0.489    0.625    0.041    0.042
##     flow             -0.346    0.090   -3.843    0.000   -0.346   -0.363
##     hzoop             0.222    0.095    2.336    0.020    0.222    0.202
##   estfish_bsmt ~                                                        
##     hzoop            -0.175    0.183   -0.953    0.341   -0.175   -0.157
##     pzoop             0.586    0.165    3.544    0.000    0.586    0.582
##     flow              0.258    0.129    1.999    0.046    0.258    0.268
##   estfish_bsot ~                                                        
##     hzoop             0.167    0.178    0.936    0.349    0.167    0.152
##     pzoop             0.439    0.161    2.734    0.006    0.439    0.443
##     flow              0.231    0.125    1.842    0.065    0.231    0.244
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .estfish_bsmt ~~                                                       
##    .estfish_bsot      0.005    0.104    0.049    0.961    0.005    0.008
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .chla              0.563    0.126    4.472    0.000    0.563    0.761
##    .potam             0.754    0.169    4.472    0.000    0.754    0.744
##    .corbic            0.893    0.200    4.472    0.000    0.893    0.844
##    .hzoop             0.559    0.125    4.472    0.000    0.559    0.712
##    .pzoop             0.203    0.045    4.472    0.000    0.203    0.213
##    .estfish_bsmt      0.679    0.152    4.472    0.000    0.679    0.700
##    .estfish_bsot      0.640    0.143    4.472    0.000    0.640    0.682
## 
## R-Square:
##                    Estimate
##     chla              0.239
##     potam             0.256
##     corbic            0.156
##     hzoop             0.288
##     pzoop             0.787
##     estfish_bsmt      0.300
##     estfish_bsot      0.318
summary(modfitnorth_dtr, standardized=T, rsq=T)
## lavaan 0.6-4 ended normally after 23 iterations
## 
##   Optimization method                           NLMINB
##   Number of free parameters                         27
## 
##                                                   Used       Total
##   Number of observations                            40          47
## 
##   Estimator                                         ML
##   Model Fit Test Statistic                       7.125
##   Degrees of freedom                                 8
##   P-value (Chi-square)                           0.523
## 
## Parameter Estimates:
## 
##   Information                                 Expected
##   Information saturated (h1) model          Structured
##   Standard Errors                             Standard
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   chla ~                                                                
##     corbic            0.353    0.152    2.325    0.020    0.353    0.349
##     potam             0.028    0.141    0.195    0.845    0.028    0.029
##   potam ~                                                               
##     flow             -0.421    0.148   -2.841    0.004   -0.421   -0.410
##   corbic ~                                                              
##     flow              0.371    0.139    2.657    0.008    0.371    0.387
##   hzoop ~                                                               
##     chla              0.214    0.131    1.628    0.103    0.214    0.242
##     corbic            0.067    0.143    0.472    0.637    0.067    0.076
##     potam             0.006    0.127    0.047    0.963    0.006    0.007
##     flow             -0.373    0.140   -2.666    0.008   -0.373   -0.437
##   pzoop ~                                                               
##     chla              0.672    0.094    7.115    0.000    0.672    0.632
##     corbic            0.355    0.100    3.551    0.000    0.355    0.329
##     potam             0.121    0.089    1.368    0.171    0.121    0.121
##     flow             -0.414    0.106   -3.916    0.000   -0.414   -0.403
##     hzoop             0.095    0.110    0.858    0.391    0.095    0.078
##   estfish_bsmt ~                                                        
##     hzoop             0.116    0.159    0.730    0.466    0.116    0.103
##     pzoop             0.544    0.127    4.286    0.000    0.544    0.580
##     flow              0.375    0.131    2.875    0.004    0.375    0.389
##   estfish_bsot ~                                                        
##     hzoop            -0.037    0.190   -0.195    0.845   -0.037   -0.032
##     pzoop             0.373    0.151    2.464    0.014    0.373    0.395
##     flow              0.176    0.155    1.131    0.258    0.176    0.181
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .estfish_bsmt ~~                                                       
##    .estfish_bsot      0.072    0.112    0.648    0.517    0.072    0.103
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .chla              0.854    0.191    4.472    0.000    0.854    0.880
##    .potam             0.911    0.204    4.472    0.000    0.911    0.832
##    .corbic            0.806    0.180    4.472    0.000    0.806    0.850
##    .hzoop             0.588    0.131    4.472    0.000    0.588    0.781
##    .pzoop             0.286    0.064    4.472    0.000    0.286    0.260
##    .estfish_bsmt      0.590    0.132    4.472    0.000    0.590    0.611
##    .estfish_bsot      0.836    0.187    4.472    0.000    0.836    0.855
## 
## R-Square:
##                    Estimate
##     chla              0.120
##     potam             0.168
##     corbic            0.150
##     hzoop             0.219
##     pzoop             0.740
##     estfish_bsmt      0.389
##     estfish_bsot      0.145
labelsnorth <- createLabels(modfitnorth, cnames)

# residuals(modfitnorth)
# modificationindices(modfitnorth)
#no potam

modsouth='chla~corbic
        corbic~flow
        hzoop~chla+corbic+flow
        pzoop~chla+corbic+flow+hzoop
        estfish_bsmt~hzoop+pzoop+flow+corbic
        estfish_bsot~hzoop+pzoop+flow+corbic
'

modfitsouth=sem(modsouth, data=filter(fdr,region=="South"))
modfitsouth_dtr=sem(modsouth, data=filter(fdr_dtr,region=="South"))
summary(modfitsouth, standardized=T, rsq=T)
## lavaan 0.6-4 ended normally after 24 iterations
## 
##   Optimization method                           NLMINB
##   Number of free parameters                         24
## 
##                                                   Used       Total
##   Number of observations                            40          47
## 
##   Estimator                                         ML
##   Model Fit Test Statistic                       0.105
##   Degrees of freedom                                 3
##   P-value (Chi-square)                           0.991
## 
## Parameter Estimates:
## 
##   Information                                 Expected
##   Information saturated (h1) model          Structured
##   Standard Errors                             Standard
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   chla ~                                                                
##     corbic            0.442    0.146    3.027    0.002    0.442    0.432
##   corbic ~                                                              
##     flow              0.301    0.143    2.101    0.036    0.301    0.315
##   hzoop ~                                                               
##     chla              0.526    0.120    4.393    0.000    0.526    0.536
##     corbic            0.329    0.128    2.572    0.010    0.329    0.327
##     flow             -0.209    0.111   -1.883    0.060   -0.209   -0.218
##   pzoop ~                                                               
##     chla              0.642    0.120    5.359    0.000    0.642    0.685
##     corbic            0.015    0.114    0.135    0.893    0.015    0.016
##     flow             -0.047    0.095   -0.497    0.619   -0.047   -0.052
##     hzoop             0.151    0.130    1.164    0.244    0.151    0.159
##   estfish_bsmt ~                                                        
##     hzoop            -0.342    0.179   -1.913    0.056   -0.342   -0.346
##     pzoop             0.318    0.171    1.854    0.064    0.318    0.308
##     flow             -0.065    0.134   -0.489    0.625   -0.065   -0.069
##     corbic            0.563    0.161    3.496    0.000    0.563    0.568
##   estfish_bsot ~                                                        
##     hzoop             0.043    0.173    0.249    0.803    0.043    0.045
##     pzoop             0.142    0.166    0.854    0.393    0.142    0.143
##     flow             -0.132    0.130   -1.017    0.309   -0.132   -0.145
##     corbic            0.457    0.156    2.928    0.003    0.457    0.480
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .estfish_bsmt ~~                                                       
##    .estfish_bsot     -0.027    0.102   -0.268    0.789   -0.027   -0.042
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .chla              0.846    0.189    4.472    0.000    0.846    0.814
##    .corbic            0.894    0.200    4.472    0.000    0.894    0.901
##    .hzoop             0.485    0.108    4.472    0.000    0.485    0.484
##    .pzoop             0.328    0.073    4.472    0.000    0.328    0.359
##    .estfish_bsmt      0.662    0.148    4.472    0.000    0.662    0.679
##    .estfish_bsot      0.622    0.139    4.472    0.000    0.622    0.691
## 
## R-Square:
##                    Estimate
##     chla              0.186
##     corbic            0.099
##     hzoop             0.516
##     pzoop             0.641
##     estfish_bsmt      0.321
##     estfish_bsot      0.309
summary(modfitsouth_dtr, standardized=T, rsq=T)
## lavaan 0.6-4 ended normally after 19 iterations
## 
##   Optimization method                           NLMINB
##   Number of free parameters                         24
## 
##                                                   Used       Total
##   Number of observations                            40          47
## 
##   Estimator                                         ML
##   Model Fit Test Statistic                       0.126
##   Degrees of freedom                                 3
##   P-value (Chi-square)                           0.988
## 
## Parameter Estimates:
## 
##   Information                                 Expected
##   Information saturated (h1) model          Structured
##   Standard Errors                             Standard
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   chla ~                                                                
##     corbic            0.151    0.159    0.951    0.341    0.151    0.149
##   corbic ~                                                              
##     flow              0.238    0.147    1.614    0.107    0.238    0.247
##   hzoop ~                                                               
##     chla              0.483    0.125    3.857    0.000    0.483    0.484
##     corbic            0.312    0.131    2.371    0.018    0.312    0.307
##     flow             -0.237    0.125   -1.892    0.059   -0.237   -0.242
##   pzoop ~                                                               
##     chla              0.579    0.139    4.174    0.000    0.579    0.572
##     corbic           -0.094    0.133   -0.707    0.480   -0.094   -0.091
##     flow             -0.085    0.123   -0.686    0.493   -0.085   -0.086
##     hzoop             0.186    0.149    1.245    0.213    0.186    0.184
##   estfish_bsmt ~                                                        
##     hzoop            -0.340    0.173   -1.967    0.049   -0.340   -0.350
##     pzoop             0.093    0.158    0.590    0.555    0.093    0.097
##     flow             -0.110    0.146   -0.751    0.452   -0.110   -0.116
##     corbic            0.415    0.160    2.597    0.009    0.415    0.420
##   estfish_bsot ~                                                        
##     hzoop             0.044    0.171    0.260    0.795    0.044    0.046
##     pzoop             0.027    0.156    0.175    0.861    0.027    0.029
##     flow             -0.172    0.145   -1.187    0.235   -0.172   -0.183
##     corbic            0.366    0.158    2.312    0.021    0.366    0.375
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .estfish_bsmt ~~                                                       
##    .estfish_bsot     -0.087    0.128   -0.676    0.499   -0.087   -0.107
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .chla              1.011    0.226    4.472    0.000    1.011    0.978
##    .corbic            0.939    0.210    4.472    0.000    0.939    0.939
##    .hzoop             0.635    0.142    4.472    0.000    0.635    0.615
##    .pzoop             0.567    0.127    4.472    0.000    0.567    0.535
##    .estfish_bsmt      0.814    0.182    4.472    0.000    0.814    0.834
##    .estfish_bsot      0.797    0.178    4.472    0.000    0.797    0.840
## 
## R-Square:
##                    Estimate
##     chla              0.022
##     corbic            0.061
##     hzoop             0.385
##     pzoop             0.465
##     estfish_bsmt      0.166
##     estfish_bsot      0.160
labelssouth <- createLabels(modfitsouth, cnames)

# residuals(modfitsouth)
# modificationindices(modfitsouth)

Nice plots

Original units

West

North

South

Detrended

West

North

South